package com.fhx.core.utils

import java.util.regex.Pattern

object StringUtil {
    /**
     * 是否是中国内的手机号
     */
    fun isChinaMobile(phone: String): Boolean {
        val regex =
            "^((13[0-9])|(14[1]|[4-9])|(15([0-3]|[5-9]))|(16([2]|[5-7]))|(17([0-3]|[5-8]))|(18[0-9])|(19[1|8|9]))\\d{8}$"
        return if (phone.length != 11) {
            false
        } else {
            val p = Pattern.compile(regex)
            val m = p.matcher(phone)
            m.matches()
        }
    }

    /**
     * 校验是否有邮箱
     */
    fun isEmail(email: String?): Boolean {
        val REGEX_EMAIL =
            "^[0-9A-Za-z][\\.-_0-9A-Za-z]*@[0-9A-Za-z]+(\\.[0-9A-Za-z]+)+$"
        return Pattern.matches(REGEX_EMAIL, email)
    }

    /**
     * 多个空白字符替换成一个空格
     */
    fun multiBlankTo1Space(str: String?): String? {
        return str?.replace(Regex("\\s+"), " ")
    }
}